    CKEDITOR.plugins.add( 'editImg_zhongzhh',
    {
    	requires : [ 'dialog','iframedialog', 'fakeobjects' ],
	    init : function( editor )
	    {
	    	var win,dialog,doc,url,editUrl;
	    	editor.addCommand( 'editImgFrame', new CKEDITOR.dialogCommand( 'editImgFrame' ) );
	    	var imgFetchIframeRegion= window.frames.document.getElementById('imgFetchIframeRegion').contentWindow;
	    	editor.on( 'paste', function(event)
    			{
	    		if($("#localPic",window.frames.document).attr("checked")){
	       		 	var pasteData= $("<div>"+event.data.html+"</div>");
	       		 	var imgOrginalSrcList= new Array();
	       		 	var imgOrginal= new Object();
	       		 	var imgParseList= $("img",pasteData);
       				afterFetchImg= function(jsonData, target){
   						var imgElement;
       					var imgInEditorList= target.document.getElementsByTag("img");
       					for(var key in jsonData){
           					for(var i=0; i< imgInEditorList.count();i++){
           						imgElement= imgInEditorList.getItem(i);
           						if(imgElement.getAttribute("orginal")== key){
           							imgElement.setAttribute("data-cke-saved-src",jsonData[key].url);
           							imgElement.setAttribute("src",jsonData[key].url);
           							imgElement.setStyle("background","");
           							imgElement.setAttribute("alt",jsonData[key].title);
           							imgElement.removeAttribute("orginal");
           						}
           					}
       					}
       				}
	       		 	if(imgParseList.length!=0){
		       		 	for(var i=0; i< imgParseList.length;i++){
		        /*        	var reg= new RegExp("^http://img[\\d]{3,}.(photo.21cn|21cnimg).com.*","gmi");*/
		                	var reg= new RegExp("^http://image.qiaoliba.com.*","gmi");
		                	if(!reg.exec($(imgParseList[i]).attr("src"))){
			       		    	var postUrlString="";
			       		    	var postAltString="";
			       		 		imgOrginal.src= $(imgParseList[i]).attr("src");
			       		 		if($(imgParseList[i]).attr("alt")){
				       		 		imgOrginal.alt= $(imgParseList[i]).attr("alt");
			       		 		}
			       		 		else{
			       		 			imgOrginal.alt= $("#title",window.frames.document).val();
			       		 		}
			       		 		postUrlString= imgOrginal.src;
			       		 		postAltString= imgOrginal.alt;
			       		 		imgFetchIframeRegion.pictureFetch(postUrlString,postAltString,"",event.editor);
			       		 		imgOrginalSrcList.push($(imgParseList[i]).attr("src"));
		                	   }
		       		 	}
		       		 	for(var i=0; i< imgOrginalSrcList.length; i++){
			       		 	for(var j=0; j< imgParseList.length; j++){
			       		 		if($(imgParseList[j]).attr("src")== imgOrginalSrcList[i]){
			       		 			$(imgParseList[j]).attr("orginal",$(imgParseList[j]).attr("src"));
			       		 			$(imgParseList[j]).attr("src","/css/bgimg/transparent.gif");
			       		 			$(imgParseList[j]).css("background","url('/css/bgimg/loader.gif') no-repeat scroll 50% 50% #EEEEEE");
			       		 		}
			       		 	}
		       		 	}
       		 			event.data.html= pasteData.html();
	       		 	}
	    		}
    			});
	    
	    var dialogDefinition =
			{
				buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ],
				onShow : function()
                {
		    		url= this.getParentEditor().getSelection().getCommonAncestor().getHtml();
                },
				onOk: function(){
					win= this.getContentElement('iframe').getElement().$.contentWindow;
					if(win.getResult().url== undefined){
						alert('请选择图片!');
						return false;
					}
					else{
						var result="<img src='"+win.getResult().url+"' alt='"+window.frames.window.editImgAlt+"'"+"/>";
						this.getParentEditor().insertHtml(result);
						
					}
				}
			};
	    CKEDITOR.dialog.addIframe( 'editImgFrame', '编辑图片','/jsp/resource/picture/editPicture.jsp',750,420,
	    	function(){
	    			},dialogDefinition
	    	);
	    
	    if(editor.addMenuItems)  //添加menu子项
	    {
	      editor.addMenuItems(  //have to add menu item first
	           {
	               editImg:  //name of the menu item
	               {
	                   label: '编辑图片',  
	                   command: 'editImgFrame', //点击执行的命令
	                   icon: 'images/edit.gif',
	                   group: 'imgControl_zhongzhh',  //通过group可以设定本菜单项所属的组，多个组结合可以实现多层菜单。虽然这里不需要多层菜单，但是group必须定义
	                   onClick:function(item){
	                	   window.frames.window.editImgUrl=this.editor.getSelection().getSelectedElement().$.src;
	                	   window.frames.window.editImgAlt=this.editor.getSelection().getSelectedElement().$.alt;
	                	   var reg= new RegExp("^http://img[\\d]{3,}.(21cnimg).com.*","gmi");
	                	   if(!reg.exec(window.frames.window.editImgUrl)){
	                		   alert("非图库中图片不可使用在线编辑功能！");
	                	   }
	                	   else{
		                	   this.editor.execCommand('editImgFrame');
	                	   }
	                   }
	               },
	               toBeListThumbnail:  //name of the menu item
	               {
	                   label: '设为缩略图',  
	                  // command: 'toBeListThumbnail', //点击执行的命令
	                   icon: 'images/edit.gif',
	                   group: 'imgControl_zhongzhh',  //通过group可以设定本菜单项所属的组，多个组结合可以实现多层菜单。虽然这里不需要多层菜单，但是group必须定义
	                   onClick:function(item){
	                	    $("#listPage",window.frames.document).attr('src',this.editor.getSelection().getSelectedElement().$.src);
	                	    $("#listPage",window.frames.document).attr('imgId',this.editor.getSelection().getSelectedElement().getAttribute('imgid'));
	                	    $("#listPage",window.frames.document).attr('alt',this.editor.getSelection().getSelectedElement().$.alt);
	                	    $('#listThumbnailValue',window.frames.document).val(this.editor.getSelection().getSelectedElement().$.src);
	                		if($("#switchThumbnail",window.frames.document).hasClass("hideThumbnailBar")){
	                			$(".vt").toggle();
	                			$("#switchThumbnail",window.frames.document).removeClass("hideThumbnailBar").addClass("showThumbnailBar");
	                		}
	                   }
	               }
	           });
	    }
	    if(editor.contextMenu)
	    {
	           editor.contextMenu.addListener(function(element, selection)  //添加右键菜单响应
	           {
	        	   if ( !element || !element.is( 'img' ) || element.data( 'cke-realelement' ) || element.isReadOnly() ){ 
	        		   //如果在ckeditor编辑框内元素之外的地方按右键，不会反回任何信息（即不显示该菜单项）
	                      return null;
	               }
	               return { editImg: CKEDITOR.TRISTATE_ON,toBeIndexThumbnail: CKEDITOR.TRISTATE_ON,toBeListThumbnail: CKEDITOR.TRISTATE_ON,toBeOtherThumbnail: CKEDITOR.TRISTATE_ON };
	    				//TRISTATE_ON意味着该菜单项可用，如果是TRISTATE_OFF则是灰色的不可用，TRISTATE_DISABLED彻底不能用
	           });
	     }
	    }
    } );
